package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

// <bean id="userService" class="com.itheima.service.impl.UserServiceImpl">
//@Component("userService")
@Service("userServ+ice")

public class UserServiceImpl implements UserService {
    @Value("${jdbc.driver}")
    private String driver;
// <property name="userDao" ref="userDao"></property>
    @Autowired//按照数据类型从Spring容器中进行配置的
    @Qualifier("userDao") //是按照id值从容器中进行配置的 但是主要此处@Qualifiter结合@Autowired一起使用
//    @Resource(name="userDao")相当于前面两个

    private UserDao userDao;

//    public UserServiceImpl(UserDao userDao) {
//        this.userDao = userDao;
//    }
//
//    public UserServiceImpl() {
//    }

//        public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }
    @PostConstruct
    public void init(){
        System.out.println("service对象的初始化方法");
    }
    @PreDestroy
    public void destory(){
        System.out.println("service对象的销毁方法");
    }
    public void save() {
        System.out.println(driver);
        userDao.save();
    }
}
